/*
 * Filename: LibListAdapter.java
 * Description: This class is used to arrange and match library images and pictures.
 * GridView in LibTabListActivity.java uses this adapter. 
 */

package edu.usc.libtalk.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import edu.usc.libtalk.R;

public class LibListAdapter extends BaseAdapter {
    private Context mContext;

    public LibListAdapter(Context c) {
        mContext = c;
    }

    public int getCount() {
        return mLibImages.length;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        
    	View grid;
    	    
    	if(convertView==null){
    		grid = new View(mContext);
    	    LayoutInflater inflater= (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);    	    
    	    grid=inflater.inflate(R.layout.lib_list_item, parent, false);
    	}else{
    		grid = (View)convertView;
    	}
    	   
    	ImageView imageView = (ImageView)grid.findViewById(R.id.lib_list_image);
    	TextView textView = (TextView)grid.findViewById(R.id.lib_list_text);
    	imageView.setImageResource(mLibImages[position]);
    	textView.setText(mLibNames[position]);

    	return grid;   
    }

    // references to USC libraries' image
    private Integer[] mLibImages = {
            R.drawable.ic_doheny_front, R.drawable.ic_leavy_front,
            R.drawable.ic_ssl_library, R.drawable.ic_vkc_library,
    };
    
    // references to USC libraries' name
    private Integer[] mLibNames = {
            R.string.doheny, R.string.leavey,
            R.string.ssl, R.string.vkc,
    }; 
}